home *** CD-ROM | disk | FTP | other *** search
- Imports System.Data
- Imports System.Data.OleDb
-
- Public Class DataGridForm
- Inherits System.Windows.Forms.Form
-
- #Region " Windows Form Designer generated code "
-
- Public Sub New()
- MyBase.New()
-
- 'This call is required by the Windows Form Designer.
- InitializeComponent()
-
- 'Add any initialization after the InitializeComponent() call
-
- End Sub
-
- 'Form overrides dispose to clean up the component list.
- Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
- If disposing Then
- If Not (components Is Nothing) Then
- components.Dispose()
- End If
- End If
- MyBase.Dispose(disposing)
- End Sub
- Friend WithEvents Label1 As System.Windows.Forms.Label
- Friend WithEvents btnFirst As System.Windows.Forms.Button
- Friend WithEvents lblRecord As System.Windows.Forms.Label
- Friend WithEvents btnNext As System.Windows.Forms.Button
- Friend WithEvents btnLast As System.Windows.Forms.Button
- Friend WithEvents btnPrevious As System.Windows.Forms.Button
- Friend WithEvents txtName As System.Windows.Forms.TextBox
- Friend WithEvents Label2 As System.Windows.Forms.Label
- Friend WithEvents txtState As System.Windows.Forms.TextBox
- Friend WithEvents Label3 As System.Windows.Forms.Label
- Friend WithEvents txtCity As System.Windows.Forms.TextBox
- Friend WithEvents grdTitles As System.Windows.Forms.DataGrid
-
- 'Required by the Windows Form Designer
- Private components As System.ComponentModel.Container
-
- 'NOTE: The following procedure is required by the Windows Form Designer
- 'It can be modified using the Windows Form Designer.
- 'Do not modify it using the code editor.
- <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
- Me.btnLast = New System.Windows.Forms.Button()
- Me.txtCity = New System.Windows.Forms.TextBox()
- Me.Label1 = New System.Windows.Forms.Label()
- Me.btnPrevious = New System.Windows.Forms.Button()
- Me.Label3 = New System.Windows.Forms.Label()
- Me.btnFirst = New System.Windows.Forms.Button()
- Me.btnNext = New System.Windows.Forms.Button()
- Me.txtState = New System.Windows.Forms.TextBox()
- Me.lblRecord = New System.Windows.Forms.Label()
- Me.Label2 = New System.Windows.Forms.Label()
- Me.txtName = New System.Windows.Forms.TextBox()
- Me.grdTitles = New System.Windows.Forms.DataGrid()
- CType(Me.grdTitles, System.ComponentModel.ISupportInitialize).BeginInit()
- Me.SuspendLayout()
- '
- 'btnLast
- '
- Me.btnLast.Location = New System.Drawing.Point(344, 80)
- Me.btnLast.Name = "btnLast"
- Me.btnLast.Size = New System.Drawing.Size(48, 32)
- Me.btnLast.TabIndex = 11
- Me.btnLast.Text = ">>"
- '
- 'txtCity
- '
- Me.txtCity.Location = New System.Drawing.Point(208, 40)
- Me.txtCity.Name = "txtCity"
- Me.txtCity.Size = New System.Drawing.Size(160, 24)
- Me.txtCity.TabIndex = 0
- Me.txtCity.Text = ""
- '
- 'Label1
- '
- Me.Label1.Location = New System.Drawing.Point(24, 16)
- Me.Label1.Name = "Label1"
- Me.Label1.Size = New System.Drawing.Size(152, 16)
- Me.Label1.TabIndex = 1
- Me.Label1.Text = "Name"
- '
- 'btnPrevious
- '
- Me.btnPrevious.Location = New System.Drawing.Point(160, 80)
- Me.btnPrevious.Name = "btnPrevious"
- Me.btnPrevious.Size = New System.Drawing.Size(48, 32)
- Me.btnPrevious.TabIndex = 8
- Me.btnPrevious.Text = "<"
- '
- 'Label3
- '
- Me.Label3.Location = New System.Drawing.Point(208, 16)
- Me.Label3.Name = "Label3"
- Me.Label3.Size = New System.Drawing.Size(152, 16)
- Me.Label3.TabIndex = 1
- Me.Label3.Text = "City"
- '
- 'btnFirst
- '
- Me.btnFirst.Location = New System.Drawing.Point(112, 80)
- Me.btnFirst.Name = "btnFirst"
- Me.btnFirst.Size = New System.Drawing.Size(48, 32)
- Me.btnFirst.TabIndex = 7
- Me.btnFirst.Text = "<<"
- '
- 'btnNext
- '
- Me.btnNext.Location = New System.Drawing.Point(296, 80)
- Me.btnNext.Name = "btnNext"
- Me.btnNext.Size = New System.Drawing.Size(48, 32)
- Me.btnNext.TabIndex = 10
- Me.btnNext.Text = ">"
- '
- 'txtState
- '
- Me.txtState.Location = New System.Drawing.Point(376, 40)
- Me.txtState.Name = "txtState"
- Me.txtState.Size = New System.Drawing.Size(96, 24)
- Me.txtState.TabIndex = 0
- Me.txtState.Text = ""
- '
- 'lblRecord
- '
- Me.lblRecord.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
- Me.lblRecord.Location = New System.Drawing.Point(208, 80)
- Me.lblRecord.Name = "lblRecord"
- Me.lblRecord.Size = New System.Drawing.Size(88, 32)
- Me.lblRecord.TabIndex = 9
- Me.lblRecord.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
- '
- 'Label2
- '
- Me.Label2.Location = New System.Drawing.Point(376, 16)
- Me.Label2.Name = "Label2"
- Me.Label2.Size = New System.Drawing.Size(56, 16)
- Me.Label2.TabIndex = 1
- Me.Label2.Text = "State"
- '
- 'txtName
- '
- Me.txtName.Location = New System.Drawing.Point(24, 40)
- Me.txtName.Name = "txtName"
- Me.txtName.Size = New System.Drawing.Size(168, 24)
- Me.txtName.TabIndex = 0
- Me.txtName.Text = ""
- '
- 'grdTitles
- '
- Me.grdTitles.AlternatingBackColor = System.Drawing.Color.LightGray
- Me.grdTitles.BackColor = System.Drawing.Color.DarkGray
- Me.grdTitles.BackgroundColor = System.Drawing.Color.Silver
- Me.grdTitles.CaptionBackColor = System.Drawing.Color.White
- Me.grdTitles.CaptionFont = New System.Drawing.Font("Verdana", 10!)
- Me.grdTitles.CaptionForeColor = System.Drawing.Color.Navy
- Me.grdTitles.CaptionText = "Titles"
- Me.grdTitles.DataMember = ""
- Me.grdTitles.ForeColor = System.Drawing.Color.Black
- Me.grdTitles.GridLineColor = System.Drawing.Color.Black
- Me.grdTitles.GridLineStyle = System.Windows.Forms.DataGridLineStyle.None
- Me.grdTitles.HeaderBackColor = System.Drawing.Color.Silver
- Me.grdTitles.HeaderForeColor = System.Drawing.Color.Black
- Me.grdTitles.LinkColor = System.Drawing.Color.Navy
- Me.grdTitles.Location = New System.Drawing.Point(19, 136)
- Me.grdTitles.Name = "grdTitles"
- Me.grdTitles.ParentRowsBackColor = System.Drawing.Color.White
- Me.grdTitles.ParentRowsForeColor = System.Drawing.Color.Black
- Me.grdTitles.SelectionBackColor = System.Drawing.Color.Navy
- Me.grdTitles.SelectionForeColor = System.Drawing.Color.White
- Me.grdTitles.Size = New System.Drawing.Size(448, 192)
- Me.grdTitles.TabIndex = 12
- '
- 'DataGridForm
- '
- Me.AutoScaleBaseSize = New System.Drawing.Size(7, 17)
- Me.ClientSize = New System.Drawing.Size(480, 341)
- Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.Label3, Me.txtCity, Me.Label2, Me.txtState, Me.btnFirst, Me.lblRecord, Me.btnNext, Me.btnLast, Me.btnPrevious, Me.Label1, Me.txtName, Me.grdTitles})
- Me.Font = New System.Drawing.Font("Microsoft Sans Serif", 11!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
- Me.Name = "DataGridForm"
- Me.Text = "AdoNetBindingForm"
- CType(Me.grdTitles, System.ComponentModel.ISupportInitialize).EndInit()
- Me.ResumeLayout(False)
-
- End Sub
-
- #End Region
-
- ' initiate binding when the form loads
-
- Private Sub Form_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
- CreateDataSet()
- InitializeBinding()
- End Sub
-
- Dim dsBiblio As New DataSet()
- Dim bmb As BindingManagerBase
-
- ' create a DataSet with the Publishers table
-
- Sub CreateDataSet()
- ' Open a connection to the Biblio.mdb database.
- Dim cn As New OleDbConnection(BiblioConnString)
- cn.Open()
-
- ' Create a data adapter for the Publisher table.
- Dim daPublishers As New OleDbDataAdapter("SELECT * FROM Publishers", cn)
- ' Fill the DataSet object with Publishers data.
- daPublishers.Fill(dsBiblio, "Publishers")
-
- ' Create a data adapter for the Titles table.
- Dim daTitles As New OleDbDataAdapter("SELECT * FROM Titles", cn)
- ' Fill the DataSet object with Titles data.
- daTitles.Fill(dsBiblio, "Titles")
-
- ' Create a Relation between the two table
- dsBiblio.Relations.Add("PubTitles", dsBiblio.Tables("Publishers").Columns("PubID"), dsBiblio.Tables("Titles").Columns("PubId"))
-
- ' Close the connection
- cn.Close()
- End Sub
-
- ' connect all fields to the data source
-
- Sub InitializeBinding()
- ' Bind fields to database fields.
- txtName.DataBindings.Add("Text", dsBiblio, "Publishers.Name")
- txtCity.DataBindings.Add("Text", dsBiblio, "Publishers.City")
- txtState.DataBindings.Add("Text", dsBiblio, "Publishers.State")
- ' Bind the Data Grid.
- grdTitles.DataSource = dsBiblio
- grdTitles.DataMember = "Publishers.PubTitles"
-
- ' get a reference to the BindingManagerBase object.
- bmb = Me.BindingContext(dsBiblio, "Publishers")
-
- ' Force a refresh.
- bmb.Position = bmb.Count
- bmb.Position = 0
- End Sub
-
- ' navigational buttons
-
- Private Sub btnFirst_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFirst.Click
- bmb.Position = 0
- End Sub
-
- Private Sub btnPrevious_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrevious.Click
- bmb.Position -= 1
- End Sub
-
- Private Sub btnNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNext.Click
- bmb.Position += 1
- End Sub
-
- Private Sub btnLast_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLast.Click
- bmb.Position = bmb.Count
- End Sub
- End Class
-